package account.model;

import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import tools.language.MentionAccounts;
import dao.account.DataLayerAccount;
import dao.server.DataLoadIP;
import account.docent.view.DocentView;
import account.student.view.StudentViewSmall;
import account.view.InloggenView;

public class InloggenModel {

	public static InloggenModel instance;

	public static InloggenModel getInstance() {
		if (instance == null) {
			instance = new InloggenModel();
		}
		return instance;
	}

	public boolean Inloggen() {
		//laden van gegevens uit database
		SubTeam.getInstance().loadAccounts();

		Account a = new Account(0, 
				InloggenView.getInstance().getGebruikersnaamTF().getText(), 
				InloggenView.getInstance().getWachtwoordTF().getText());

		//gegevens controleren in de database
		if (SubTeam.getInstance().checkAccount(a)) {
			//inlog voor docenten = typenummer 2
			if(SubTeam.getInstance().getAcc().getTypenummer() == 2){
				DocentView.getInstance();
				InloggenView.getInstance().frame.dispose();
			}

			//inlog voor studenten = typenummer 1
			if(SubTeam.getInstance().getAcc().getTypenummer() == 1){
				StudentViewSmall.getInstance().setVisible(true);
				InloggenView.getInstance().frame.dispose();
			} 
			MentionAccounts.getInstance().succesInloggen();
		}
		//gegevens onjuist
		else{
			MentionAccounts.getInstance().errorInloggen();
		}
		return false;
	}
}
